In [1]:
from pathlib import Path

from ipyniivue import download_dataset

BASE_API_URL = "https://niivue.com/demos/images/"
DATA_FOLDER = Path("images")

# Download data for example
download_dataset(
    BASE_API_URL,
    DATA_FOLDER,
    files=[
        "mpld_asl.nii.gz",
    ],
)
mpld_asl.nii.gz already exists.
Dataset downloaded successfully to images.
In [2]:
import ipywidgets as widgets

from ipyniivue import NiiVue, SliceType

try:
    import nibabel as nib
except ModuleNotFoundError:
    !pip install nibabel
    import nibabel as nib

example = DATA_FOLDER / "mpld_asl.nii.gz"
volumes = [
    {
        "path": example,
        "colormap": "gray",
        "opacity": 1.0,
    },
]
nv = NiiVue(slice_type=SliceType.MULTIPLANAR)
nv.load_volumes(volumes)

nvols = nib.load(str(example)).shape[-1]

slider = widgets.IntSlider(min=0, max=nvols - 1, description="Volume")


def update_frame(*args):
    """Select the frame corresponding to the slider value."""
    nv.volumes[0].frame_4d = slider.value


slider.observe(update_frame, "value")

display(slider)
display(nv)